package com.fengstyle.tool.common;

import org.apache.pdfbox.multipdf.Splitter;
import org.apache.pdfbox.pdmodel.PDDocument;

import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * PDF文件拆分
 */
public class SplitPDF {

    public static void main(String[] args) throws IOException {

        Splitter splitter = new Splitter();
        //设置起始页、结束页、每个文件的页数
        splitter.setStartPage(1);
        splitter.setEndPage(32);
        splitter.setSplitAtPage(30);
        PDDocument source = PDDocument.load(new File("D:\\work\\Desktop\\test.pdf"));
        List<PDDocument> list = splitter.split(source);
        for (int i = 0; i < list.size(); i++) {
            PDDocument document = list.get(i);
            document.save("D:\\work\\Desktop\\test" + i + ".pdf");
        }

    }
}
